<template>
  <div>
    <data-table
      ref="pagingTable"
      :options="options"
      :list-query="listQuery"
    >
      <template slot="filter-content">
        <div style="float:left;padding-top: -5px">
        <el-button type="primary" icon="el-icon-document-add"  @click="addFlow('')">新建流程</el-button>
          </div>
        <el-input v-model="listQuery.params.name" placeholder="流程名称" style="width: 200px;" class="filter-item" />

      </template>

      <template slot="data-columns">
        <el-table-column
          label="流程名称"
          prop="name"
        >
          <template slot-scope="scope">
            <el-link type="primary" @click="addFlow(scope.row.id)">
              {{ scope.row.name }}
            </el-link>
          </template>
        </el-table-column>

        <el-table-column
          label="流程KEY"
          prop="modelKey"
          align="center"
        />
        <el-table-column
          label="流程版本"
          prop="version"
          align="center"
        />

        <el-table-column
          label="更新时间"
          prop="updateTime"
          align="center"
        />
        <el-table-column
          label="操作"
          prop="extendName"
          width="140"
          align="center"
        >
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" content="设计" placement="top-start">
            <el-button size="mini" type="primary" icon="el-icon-edit" circle @click="addFlow(scope.row.id)" />
          </el-tooltip>
          <el-tooltip v-permission="['flow:model:del']" class="item" effect="dark" content="删除" placement="top-start">
            <el-button size="mini" type="danger" icon="el-icon-delete" circle @click="delFlow(scope.row.id)" />
          </el-tooltip>
          <el-tooltip class="item" v-if="scope.row.modelStatus == 0" effect="dark" content="发布流程" placement="top-start">
            <el-button size="mini" type="success" icon="el-icon-upload2" circle @click="fbFlow(scope.row.id)" />
          </el-tooltip>
        </template>
        </el-table-column>
      </template>
    </data-table>
    <el-dialog title="流程设计" @destroy-on-close="true"	 :visible.sync="addFlowVisible" width="80%" top="1vh" @close="closeVersion">
      <flow-form :id="id" />
    </el-dialog>
  </div>
</template>

<script>
import { deleteById, fbFlow } from '@/api/flowable/flowable'
import DicListSelect from '@/components/DicListSelect'
import DataTable from '@/components/DataTable'
import permission from '@/directive/permission/index.js'
import FlowForm from '@/views/admin/flowable/model/form'
export default {
  directives: { permission },
  components: { FlowForm, DataTable,DicListSelect },
  data() {
    return {
      addFlowVisible: false,
      userData: {},
      disabled: false,
      id: '',
      listQuery: {
        current: 1,
        size: 10,
        params: {

        }
      },
      options: {
        // 可批量操作
        multi: true,
        multiActions: [],
        /* delete: {
          enable: true,
          permission: 'flow:model:del',
          url: '/api/flowable/model/delete'
        }, */
        // 列表请求URL
        listUrl: '/api/flowable/model/paging'
      }
    }
  },
  methods: {
    addFlow(id) {
      this.id = id
      this.addFlowVisible = true
    },
    closeVersion() {
      this.addFlowVisible = false
      this.$refs.pagingTable.getList()
    },
    delFlow(id) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteById(id).then(res => {
          this.$notify({
            title: '成功',
            message: '删除成功！',
            type: 'success',
            duration: 2000
          })
          this.$refs.pagingTable.getList()
        })
      }).catch(() => {

      })
    },
    fbFlow(id) {
      this.$confirm('确定要发布流程吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        fbFlow(id).then(res => {
          this.$notify({
            title: '成功',
            message: '发布成功！',
            type: 'success',
            duration: 2000
          })
          this.$refs.pagingTable.getList()
        })
      }).catch(() => {

      })
    }
  }
}
</script>
